#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : gtmsAutoTestProject 
@File    : shop_table_code_interface.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/8/24 11:00 
@Describe: 获取门店桌位码接口入口
"""
from fastapi import APIRouter
from starlette.responses import FileResponse
from Comm.logUtils.logControl import LogHandler
from FastApi.dto.middle.operate.shop.shop_table_code_dto import ShopTableCodeDto
from FastApi.server.middle.operate.shop.shop_table_code_server import ShopTableCodeServer

logger = LogHandler().get_logger()
shopTableCode_router = APIRouter()


@shopTableCode_router.post("/table/code", name="空闲台位桌码")
async def shopTableCode(payload: ShopTableCodeDto):
    logger.info('请求参数:[{}]'.format(payload))
    middle_shop_request = ShopTableCodeServer(payload.brandCode, payload.environment)
    table_code_path = middle_shop_request.get_pos_idle_table()
    if type(table_code_path) is dict:
        return table_code_path
    else:
        return FileResponse(table_code_path, media_type='image/png')
